// src/services/apiService.js
import apiClient from './api'

// ... (existing methods) ...

// --- 新增: 公告模块 API 服务 ---
/**
 * 获取所有正常状态的公告列表 (按创建时间降序)
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getActiveAnnouncements = async () => {
  return await apiClient.get('/announcements')
}

/**
 * 分页获取所有正常状态的公告列表 (按创建时间降序)
 * @param {Object} params - 查询参数 (page, size)
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getActiveAnnouncementsPaginated = async (params = {}) => {
  return await apiClient.get('/announcements/paginated', { params })
}

/**
 * 根据 ID 获取单个正常状态的公告详情
 * @param {number} id - 公告 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getActiveAnnouncementById = async (id) => {
  return await apiClient.get(`/announcements/${id}`)
}

/**
 * (管理员) 创建新公告
 * @param {Object} announcementData - 公告数据 { title, content, type }
 * @returns {Promise<AxiosResponse<any>>}
 */
export const createAnnouncement = async (announcementData) => {
  return await apiClient.post('/announcements', announcementData)
}

/**
 * (管理员) 分页获取所有公告列表 (包括已删除)
 * @param {Object} params - 查询参数 (page, size)
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getAllAnnouncements = async (params = {}) => {
  return await apiClient.get('/announcements/admin/all', { params })
}

/**
 * (管理员) 根据 ID 获取单个公告详情 (包括已删除)
 * @param {number} id - 公告 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const getAnnouncementById = async (id) => {
  return await apiClient.get(`/announcements/admin/${id}`)
}

/**
 * (管理员) 更新公告
 * @param {number} id - 公告 ID
 * @param {Object} announcementData - 更新的公告数据 { title, content, type }
 * @returns {Promise<AxiosResponse<any>>}
 */
export const updateAnnouncement = async (id, announcementData) => {
  return await apiClient.put(`/announcements/${id}`, announcementData)
}

/**
 * (管理员) 删除公告 (软删除)
 * @param {number} id - 公告 ID
 * @returns {Promise<AxiosResponse<any>>}
 */
export const deleteAnnouncement = async (id) => {
  return await apiClient.delete(`/announcements/${id}`)
}

// --- ---
